package com.inspire.tank.cor;

import com.inspire.tank.GameObject;
import com.inspire.tank.Tank;

/**
 * @author inspire
 * @description 计算子弹和坦克相撞
 * @date 2022/6/15 23:01
 */
public class TankTankCollider implements Collider {
    @Override
    public boolean collide(GameObject gameObject1, GameObject gameObject2) {

        if (gameObject1 instanceof Tank && gameObject2 instanceof Tank) {
            Tank tank1 = (Tank) gameObject1;
            Tank tank2 = (Tank) gameObject2;
            if(tank1.getRect().intersects(tank2.getRect())){
                /*tank1.setX(tank1.getPriorX());
                tank1.setY(tank1.getPriorY());
                tank2.setX(tank2.getPriorX());
                tank2.setY(tank2.getPriorY());*/
                tank1.back();
                tank2.back();
            }
        }
        return true;

    }
}
